package member;

import java.sql.PreparedStatement;
import java.util.ArrayList;

import org.apache.ibatis.session.SqlSession;


//회원정보를 처리하기 위한 모든 제어 구조를 가지고 있는 클래스
public class MemberMyba {

	private SqlSession session; //Connection Object가 생성된 상태
	MemberVo memberVo;
	private String uploadPath = "C:\\workspace\\svn_web1403\\WebContent\\upload";
	



	public MemberMyba(){
		try{
			session=MemberFactory.getFactory().openSession();
			
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	

	
	public MemberVo view(){
		
		MemberVo vo= null;
		try{
			vo=(MemberVo)session.selectOne("member.view", memberVo.getMemberid());//한건의 데이터를 가지고 올때 selectOne
			session.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}

		return vo;
	}
	
	public ArrayList<MemberVo> list(){
		ArrayList<MemberVo> data=null;
		try{
			
			data=(ArrayList<MemberVo>)session.selectList("member.list","%"+memberVo.getFind()+"%");
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return data;

	}
	
/*	public MemberVo modify(){
		MemberVo vo= null;
		try{
			vo=(MemberVo)session.selectOne("member.view", memberVo.getMemberid());//한건의 데이터를 가지고 올때 selectOne
			session.close();		
				
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return vo;
	}
	public MemberVo getMemberVo() {
		return memberVo;
	}*/
	
	
	public boolean delete(){
		boolean flag=false;

		try{
		
			if(session.delete("member.delete", memberVo.getMemberid()) >0){
				flag=true;
			
				session.commit();
			}else{
				flag=false;
			}
			
		}catch(Exception ex){
			ex.printStackTrace();
			
		}
		
		return flag;
	}

	public boolean modify(){
	
		boolean flag=false;
		try{
			System.out.println(1);
			if(session.update("member.update", memberVo) >0){
				flag=true;
				System.out.println(2);
				session.commit();

			}			
		}catch(Exception ex){
			ex.printStackTrace();
			System.out.println(3);
		}
		
		return flag;
	}




	public void setMemberVo(MemberVo memberVo) {
		this.memberVo = memberVo;
	}
	

	
}
